import {Config} from "../../utils/config";
import loadServerData from "../../settings/photoData";
// 小程序配置信息
const app = getApp();

Page({
    data: {
       // 界面定制化的配置参数
        mpName : '证件照',
        // tabBar:app.globalData.settings.tabBar,
        //功能按钮
        navData: [],
        bannerAd:{},
        // 服务器数据
        serverData:{}

    },
    // 制作证件照
    makeIdphoto() {
        wx.navigateTo({
            url: "/pages/photo/camera/camera",
        });
    },
    // 修改底色
    changeBg() {
        wx.navigateTo({
            url: "/pages/photo/background/background",
        });
    },
    // 裁剪图片
    cropperPhoto() {
        wx.navigateTo({
            url: "/pages/photo/cropper/cropper",
        });
    },
    /**压缩图片 */
    compressImage() {
        wx.navigateTo({
            url: "/pages/photo/compress/compress",
        });
    },
    onShareAppMessage(){
        const config = app.globalData.serverData.config;
        return {
            title: config['shareTitle'],
            path: config['sharePath'],
            imageUrl:config['shareImage']
        }
    },
    /* 设置回调函数,保证回调函数中的代码在onLanch代码后执行,
    解决数据加载问题
    */
    onLoad(options){
        
        if(app.globalData.serverData){
            this.onLoadAL()
        }else{
            app.callBack = (res)=>{
                this.onLoadAL()
            }
        }
    },
    /*onLanch中执行的回调函数,设置一些初始数据 */
    onLoadAL(){
        const data = app.globalData.serverData;
        this.setData({
            navData:data['shop'],
            bannerAd:data['ad'][Config.AD_POSITION_HOME],
            mpName:data['config']['mpName'],
        })
    },
    onShow(){
        loadServerData().then(res=>{
            app.globalData.serverData = res;
        });
    }
})